<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id="app">
    <table border="1">
      <tr>
        <th>序号</th>
        <th>名称</th>
        <th>价格</th>
        <th>操作</th>
        <th>小计</th>
      </tr>
      <tr v-for="(item, index) of cartdata" :key="item.id">
        <td>{{ index + 1 }}</td>
        <td>{{ item.name }}</td>
        <td>{{ item.price }}</td>
        <td>
          <button :disabled="item.num<=1" @click="item.num-=1">-</button>
          {{ item.num }}
          <button @click="item.num+=1">+</button>
          <button @click="deleteItem(index)">X</button>
        </td>
        <td>
          {{ item.price * item.num }}
        </td>
      </tr>
    </table>
  </div>
</body>
<script src="lib/vue.js"></script>
<script>
  new Vue({
    el: '#app',
    data: {
      cartdata: [{
        id: 1,
        name: '小米',
        price: 100,
        num: 1
      }, {
        id: 2,
        name: '华为',
        price: 200,
        num: 1
      }, {
        id: 3,
        name: '联想',
        price: 300,
        num: 1
      }]
    },
    methods: {
      deleteItem (index) {
        // 删除数组中的这一项
        this.cartdata.splice(index, 1)
      }
    }
  })
</script>

</html>